#!/bin/bash

homePath="/home/program/source/community"
codePath="/home/program/source/community/isc"
deployPath="/home/program/ss-isc"
devPath="/home/program/source/community/env"

gitOsc="https://github.com/liangmuxue/community.git"
app_name="ss-isc-package-all"

#################################选择打包库########################################
echo  "请选择打包库："
read -p  "production（1）  test（2） 退出（0）" choic

echo  "拉取代码..."
git stash save "s"
cd $homePath
if [ ! -d $codePath ]
then
	rm -rf $codePath
	 echo  "重新  clone git  "
	git clone $gitOsc
else
    echo  "拉取代码...1"
	cd $codePath
	git pull
fi

if [ $choic -eq 1 ]
then
	echo "打包 production"
	devPath=$devPath/production
elif [ $choic -eq 2 ]
then
	echo "打包 test"
	devPath=$devPath/test
elif [ $choic -eq 0 ]
then
	exit
else
	exit
fi

#拷贝差异化配置文件
cp -rf  $devPath/*  $deployPath/

echo  "覆盖差异化文件finished"
cd $codePath
echo  "mvn install..."
mvn clean install -Dmaven.test.skip=true
echo  "mvn install finished..."

#拷贝jar
cp -f  $codePath/isc-main/target/$app_name.jar  $deployPath/


#################################重启服务####################################

echo "kill isc app...... "
#netstat -nlp |grep :5090 |grep -v grep|awk '{print $7}' |awk -F '/' '{print $1}' |xargs kill -9
ps -ef |grep $app_name | awk '{print $2}' | xargs kill -9
echo "kill isc app......finished "

cd $deployPath

./run.sh restart

echo "start ss-isc success..."


